package main

import (
	"fmt"
	"time"
)

func expensiveOperation() int {
	defer logTime("expensiveOperation")()

	time.Sleep(time.Second * 1)

	return 42
}

func logTime(name string) func() {
	start := time.Now()
	return func() { fmt.Printf("%s took %v\n", name, time.Since(start)) }
}

func main() {
	result := expensiveOperation()

	fmt.Println(result)
}
